package com.seeyon.ctp.rest.resources;

import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import jersey.repackaged.com.google.common.collect.Maps;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.JdbcTemplate;

import com.alibaba.fastjson.JSONObject;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.kk.model.SqlAndParam;
import com.seeyon.kk.modules.ibatis.IbatisQueryDao;

/**
 * 开放给会议系统（天目神盾）使用
 * @author seeyon
 *
 */
@Path("/shkk/meetingFile")
public class MeetingFileUpload extends BaseResource {
	private static final Log log = LogFactory.getLog(MeetingFileUpload.class);	
	private JdbcTemplate jdbcTemplate=(JdbcTemplate) AppContext.getBean("kkJdbcTemplate");
	private IbatisQueryDao ibatisQueryDao=(IbatisQueryDao) AppContext.getBean("kkIbatisQueryDao");
	/**
	 * 通过会议ID与对应附件关联起来在界面显示
	 * @param params 附件相关参数
	 * @return
	 */
	@POST
	@Path("/show")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML })
	@Consumes({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML })
	public JSONObject showMeetingFile(JSONObject params) {
		log.info("==========SHKK========会议系统（天目神盾）远程调用接口-->《/shkk/meetingFile/upload》=======>>START");
		Map<String, Object> rsMap = new HashMap<String, Object>();
		String message="附件关联成功！";
		if(params!=null){
			  Map<String,Object> paramMap=Maps.newHashMap();
			  paramMap.put("attachmentId", params.get("attachmentId"));
			  paramMap.put("meetingId", params.get("meetingId"));
			  SqlAndParam sap=this.ibatisQueryDao.getSqlAndParametersFromIbatis("attachmentReferenceMeeting.update", paramMap);
			  int result=this.jdbcTemplate.update(sap.getSql(),sap.getValues());
			  if(result==0){
				   message="未找到id为"+params.get("meetingId")+"的附件信息!";
				   log.info("==========SHKK========会议系统（天目神盾）远程调用接口-->《/shkk/meetingFile/upload》=====无关联附件信息更改！");
			  }
			  rsMap.put("result", result);
		}else{
			rsMap.put("result", 0);
			message="没有传入params，附件关联失败！！";
			log.info("==========SHKK========会议系统（天目神盾）远程调用接口-->《/shkk/meetingFile/upload》========"+message);
		}
		rsMap.put("message", message);
		JSONObject jsonResult=new JSONObject(rsMap);
		log.info("==========SHKK========会议系统（天目神盾）远程调用接口-->《/shkk/meetingFile/upload》=======>>END");
		return jsonResult;
	}
}
